$(document).ready(function () {
    var userId = $('#userId').val();
    $(".face_upload").each(function () {

        var  this_ = $(this);

        // 获取选择图片的盒子
        var upload_btn =    this_.find(".upload_btn");
        var  upload_btn_id =  upload_btn.attr("id");

        // 获取装图片的盒子
        var upload_img =    this_.find(".upload_img");
        var  upload_img_id =  upload_img.attr("id");

        // 获取keyName值
        var keyName = this_.find('.file_input_value');
        var keyName_val = keyName.attr('keyName');

        var img_value = this_.find('.file_input_value').val();
        if (img_value != null && img_value != "" && img_value != undefined) {
            var img_url = "/wxapply/getMedia?mediaId=" + img_value;
            var img = this_.find(".upload_img img");
            img.attr('src', img_url);//图片链接（base64
        }
        var id = $('#wxMchId').val();
        $.fileUpload({
            filebutton: "#"+upload_btn_id,
            previewZoom: "#"+upload_img_id,
            keyName_val: keyName_val,
            httpUrl: "/wxapply/media_upload",
            userId: userId,
            id: id
        });

    });

    // 服务描述开始
    $('.describe').on('click',function () {
       $('.describe_ul').toggle();
    });
    $('.describe_ul li').on('click',function () {
        var describeVal = $('.describe_ul li').eq($(this).index()).text();
        $('.describe span').text(describeVal);
        $('.describe input').val(describeVal);
    });
    // 服务描述结束

    // 提交进件
    $('.preservation').on('click',function () {
        var formData = $('form').serializeArray();
        // 联系人校验
        var contact = $('input[name=contact]').val();
        var contact_phone = $('input[name=contact_phone]').val();
        var contact_email = $('input[name=contact_email]').val();

        // 经营信息校验
        var merchant_shortname = $('input[name=merchant_shortname]').val();
        var store_name = $('input[name=store_name]').val();
        var store_address_code = $('input[name=store_address_code]').val();
        var store_street = $('input[name=store_street]').val();
        var store_entrance_pic =  $('#bu_img img').attr("src");

        var indoor_pic =  $('#bl_img img').attr("src");
        var service_phone = $('input[name=service_phone]').val();
        var product_desc = $('input[name=product_desc]').val();

        // 企业法人/经办人校验
        var id_card_name = $('input[name=id_card_name]').val();
        var id_card_number = $('input[name=id_card_number]').val();
        var id_card_copy = $('#bi_img img').attr("src");
        var id_card_national = $('#bp_img img').attr("src");
        var id_card_valid_time = $('input[name=id_card_valid_time]').val();

        // 结算信息校验
        var wxFinalRate = $('input[name=wxFinalRate]').val();
        var account_name = $('input[name=account_name]').val();
        var account_bank = $('input[name=account_bank]').val();
        var bank_address_code = $('input[name=bank_address_code]').val();
        var bank_name = $('input[name=bank_name]').val();
        var account_number = $('input[name=account_number]').val();

        if(!contact){
            $.toast("名字必填");
        }else if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(contact_phone))){
            $.toast("电话号码有误");
        }else if(!contact_email){
            $.toast("邮箱必填");
        }else if(!merchant_shortname){
            $.toast("商户简称必填");
        }else if(!store_name){
            $.toast("门店名称必填");
        }else if(!store_address_code){
            $.toast("门店省市编码必填");
        }else if(!store_street){
            $.toast("门店街道名称必填");
        }else if(!store_entrance_pic){
            $.toast("门店门口照片必传");
        }else if(!indoor_pic){
            $.toast("店内环境照片必传");
        }else if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(service_phone))){
            $.toast("客服电话有误");
        }else if(!product_desc){
            $.toast("服务描述必填");
        }else if(!id_card_name){
            $.toast("身份证姓名必填");
        }else if(!id_card_number){
            $.toast("身份证号码必填");
        }else if(!id_card_copy){
            $.toast("身份证人像面照片必传");
        }else if(!id_card_national){
            $.toast("身份证国徽面照片必传");
        }else if(!(/^\d{4}-\d{2}-\d{2}[^|]*?[|]?\d{4}-\d{2}-\d{2}$/.test(id_card_valid_time))){
            $.toast("有效期格式有误");
        }else if(!wxFinalRate){
            $.toast("微信结算费率必填");
        }else if(!account_name){
            $.toast("开户名称必填");
        }else if(!account_bank){
            $.toast("开户银行必填");
        }else if(!bank_address_code){
            $.toast("开户银行省市编码必填");
        }else if(!bank_name){
            $.toast("开户银行全称（含支行）必填");
        }else if(!account_number){
            $.toast("银行账号必填");
        }else  {
            $.post('/wxapply/subinfo',formData,function (result) {
                if(result.code==1){
                    $.toast("提交进件成功");
                }else{
                    $.toast(result.message);
                }
            });
        }
    });

    // 暂存开始
    $('.temporary_storage').on('click',function () {
        var formData = $('form').serializeArray();
        $.post('/wxmchinfo/edit',formData,function (result) {
            if(result.code==1){
                $.toast("暂存成功");
            }else{
                $.toast(result.message);
            }
        });
    });


});